﻿module Coq.MonoDevelop.Helpers.Common

open Ast

//Second parameter falls into the space of 1st parameter
let IsPartOf (pos:Lexing.Position) ((s,e):Location) = 
    if (s.Line < pos.Line && e.Line > pos.Line) then 
        true
    else if (s.Line = pos.Line && e.Line = pos.Line) then //if is on same line and pos is inbetween
            (s.Column <= pos.Column && e.Column >= pos.Column-2)
        else if (s.Line = pos.Line) then
            (s.Column <= pos.Column && e.Line > pos.Line)
        else if (e.Line = pos.Line) then
            (e.Column >= pos.Column-2 && s.Line < pos.Line )
            else
                false

//Second parameter falls into the space of 1st parameter
let IsBefore (a:Lexing.Position) (b:Lexing.Position) = 
    if (a.Line < b.Line) then true
    else if (a.Line = b.Line && a.Column <= b.Column) then true
    else false

//Calls function f on each item in list l and connects the return arrays into one
let Merge f l =
    l |> List.map f |> List.concat 

let Max a b = 
    if a > b then a else b 